#include "app_main.h"
#include "at32f403a_407_wk_config.h"
#include "wk_acc.h"
#include "wk_tmr.h"
#include "wk_usart.h"
#include "wk_gpio.h"
#include "wk_system.h"
#include "wk_dma.h"
#include "usbd_core.h"
#include "cdc_msc_class.h"
#include "cdc_msc_desc.h"
#include "usbd_int.h"
#include "ff.h"

#include "DAPA_config.h"
#include "operate_spim.h"
#include "st7735.h"
#include "board_init.h"





extern usbd_core_type usb_core_dev;

static uint8_t usb_vcp_rx_buffer[128];
static uint32_t data_len;

void usb_to_uart(void)
{
    if(rx5_flag)
    {
        rx5_flag = 0;
        int enter_retry = 100;
        do
        {
            // send data to host 
            if( usb_vcp_send_data(&usb_core_dev, (uint8_t *)uart5_rx_buffer, rx5_count) == SUCCESS)
            {
                break ;
            }
            delay_100us(1);
        }while(enter_retry --);
        rx5_count = 0;
    }
    if(rx1_flag)
    {
        rx1_flag = 0;
        int enter_retry = 100;
        do
        {
            // send data to host 
            if( usb_vcp_send_data(&usb_core_dev, (uint8_t *)uart1_rx_buffer, rx1_count) == SUCCESS)
            {
                break ;
            }
            delay_100us(1);
        }while(enter_retry --);
        
        rx1_count = 0;
    }
    
    data_len = usb_vcp_get_rxdata(&usb_core_dev, usb_vcp_rx_buffer);
    if(data_len > 0)
    {
        uart1_dma_send_bytes(usb_vcp_rx_buffer, data_len);
    }
}








void app_main(void)
{
    log("Hello World\r\n");
	while(1)
	{
        
	}
}





